package com.vijay.extension.spring;

import org.springframework.beans.factory.BeanFactory;

import java.lang.reflect.Proxy;

public class SpringExtensionProxyFactory<T> {

    private Class<T> extensionInterface;

    public SpringExtensionProxyFactory(Class<T> extensionInterface) {

        this.extensionInterface = extensionInterface;
    }


    public T newInstance(SpringExtensionProxy proxy) {

        return (T) Proxy.newProxyInstance(extensionInterface.getClassLoader(), new Class[]{extensionInterface}, proxy);

    }


    public T newInstance(BeanFactory factory) {
        SpringExtensionProxy proxy = new SpringExtensionProxy(extensionInterface, factory);
        return newInstance(proxy);
    }


}
